define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		//商品数据
		function get_data_goods_search(result) {
				if(HTTP_ISLOGIC) {
					result = '{"success": true,"msg": "","result": {"goods": [' +
						'{"goods_id": 1,"name": "螺丝刀","bn": "新品","store": 100,"price": 10.55,"buy_count": 20,"uptime": "2017/01/01 09:00:00","store_id": 1,"image_default": "img/upload/pro-img01.jpg","freez": 10,"is_tui": true,"is_new": true},' +
						'{"goods_id": 2,"name": "螺丝刀","bn": "热卖","store": 100,"price": 11.55,"buy_count": 20,"uptime": "2017/01/01 09:00:00","store_id": 2,"image_default": "img/upload/pro-img01.jpg","freez": 10,"is_tui": true,"is_new": false}]},' +
						'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
					return JSON.parse(result);
				} else {
					return result;
				}

			};
			
		//可选品牌一览	
		function get_data_brandList(result) {
				if(HTTP_ISLOGIC) {
					result = '{"success":true,"msg":"","result":{"brand":[{"id":"001","name":"世达"},{"id":"002","name":"博士"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
					return JSON.parse(result);
				} else {
					return result;
				}

			};	
			
			
		//返回信息
		return {
			goods_search: function(nPage, pagelimit, orderby, callback) {
				Http.post({
					method: 'goods.insales.search',
					nPage: nPage,
					pagelimit:pagelimit,
					picSize:'CS',
					orderby: orderby
				}, function(result) {
                     if(callback)
                     callback(get_data_goods_search(result).result);
				}, function(e) {

				}, function() {

				})
			},
			//上下架
			goods_update:function(goods_id,marketable,callback){
				Http.post({
					method:'goods.marketable.update',
					session:'',
					goods_id:goods_id,
					marketable:marketable//上、下架
				},function(result){
					if(callback)
						callback(result);
				},function(e){
					
				},function(){
					
				})
			},
			//删除商品
			goods_delete:function(goods_id,callback){
				Http.post({
					method:'goods.goods.delete',
					session:'',
					goods_id:goods_id
				},function(result){
					if(callback)
						callback(result);
				},function(e){
					
				},function(){
					
				})
			},
			//品牌一览
			brandList: function(callback) {
				Http.post({
					method: 'goods.brand.getlist',
				}, function(result) {
                     if(callback)
                     callback(get_data_brandList(result).result);
				}, function(e) {

				}, function() {

				})
			}
			
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Productmanager_sale", factory);
});